#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    ListNode* removeNthFromEnd(ListNode* head, int n) {
        ListNode* newHead = new ListNode;
        newHead->next = head;
        ListNode* fast = head, * slow = newHead;
        while (n--) fast = fast->next;
        while (fast != nullptr) {
            fast = fast->next;
            slow = slow->next;
        }
        slow->next = slow->next->next;
        fast = newHead->next;
        return fast;
    }
};